var AuthRoleRigthModel = $.extend(TradeModel, {
    selRow: null,
    editor:{
        title: "属性",
        winid:'AuthRoleRigth_EditForm',
        formid:'AuthRoleRigth_EditForm_fm',
        width:720,
        height:300
    },
    postAction: 'add',
    url: '/sysmgr/authrolerigth',
    title: "标题",
    idField: "id",
    titleField: "id",
    toolbar: 'AuthRoleRigth_Toolbar',
    datagrid: 'AuthRoleRigth_Grid'
});

function ReloadAuthRoleList() {
    $('#AuthRole_Grid').datagrid('reload');
}


function ReloadAuthRoleRigthList() {
    $('#AuthRoleRigth_Grid').datagrid('reload');
}


AuthRoleRigthModel.reload =function() {
    ReloadAuthRoleRigthList();
    $('#AuthRoleRigth_EditForm').dialog('close');
}


function fun_FindRowById(id) {
    var cRows = $('#AuthRoleRigth_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][AuthRoleRigthModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function ShowAuthRoleRigthEditForm(id) {
    AuthRoleRigthModel.selRow = fun_FindRowById(id);
    if (AuthRoleRigthModel.selRow == null) {
        AuthRoleRigthModel.selRow={};
        AuthRoleRigthModel.postAction = 'add';
    }
    else {
        AuthRoleRigthModel.postAction = 'update';
    }

    $('#AuthRoleRigth_EditForm_fm').form('clear' );
    $('#AuthRoleRigth_EditForm_fm').form('load', AuthRoleRigthModel.selRow);
    $('#AuthRoleRigth_EditForm').dialog({
        top: "50px",
        resizable: false,
        maximizable: false
    })
        .dialog('open')
        .dialog('setTitle', (AuthRoleRigthModel.postAction == 'Add') ? '新增' + AuthRoleRigthModel.title : '修改' + AuthRoleRigthModel.selRow[AuthRoleRigthModel.titleField]);
}
function SaveAuthRoleRigth() {
    AuthRoleRigthModel.submit();

}
function DelAuthRoleRigth( id,title) {
    AuthRoleRigthModel.del(id,title);
}

function AuthRoleSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#AuthRole_Grid').datagrid('reload');
    }

}
function AuthRoleRigthSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#AuthRoleRigth_Grid').datagrid('reload');
    }

}



$(function () {

    $('#AuthRole_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: true,
        fitColumns: true,
        pagination: true,
        method: 'post',
        idField: 'id',
        url: Onluy.basePath()+ '/sysmgr/authrole/list',
        loader:AuthRoleRigthModel.Loader,
        toolbar: '#AuthRole_Toolbar',
        columns: [
            [
                //{ field: 'id', title: '编码', width:40, align: 'center',sortable:true },
                { field: 'roleName', title: '角色列表', width:100, align: 'left',sortable:true }
            ]
        ],
        onLoadError: function (res) {
            AuthRoleRigthModel.ShowException(res);
        },
        onLoadSuccess: function (data) {
            if(data.success){
            }
            else{
                $.messager.alert('提示', data.msg );
            }
        },
        onSelect: function (rowIndex, rowData) {
            ReloadAuthRoleRigthList();
        },
        onBeforeLoad: function (param) {
            param['catchKey'] = Math.random();
            param['name'] = $('#AuthRole_ss').searchbox('getName');
            param['value'] = $('#AuthRole_ss').searchbox('getValue');
        }
    });
    //设置分页控件
    var p = $('#AuthRole_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '', //页数文本框前显示的汉字
        afterPageText: '{pages}',
        displayMsg: '{from}-{to}/{total}',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });



    $('#AuthRoleRigth_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: false,
        checkbox: true,
        fitColumns: true,
        pagination: true,
        method: 'post',
        idField: AuthRoleRigthModel.idField,
        treeField: AuthRoleRigthModel.titleField,
        url: Onluy.basePath()+AuthRoleRigthModel.url+'/list',
        loader:AuthRoleRigthModel.Loader,
        loadFilter: function(res){
            var i=0;
            for(i=0;i<res.rows.length;i++){
                if(res.rows[i].ck>0){
                    res.rows[i].checked=true  ;
                }else{
                    res.rows[i].checked=false  ;
                }
            }
            return res;
        },
        toolbar: '#AuthRoleRigth_Toolbar',
        columns: [
            [
                {field:'ck',checkbox:true },
                { field: 'memo', title: '说明', width:100, align: 'left' } ,
                { field: 'dataid', title: '数据标识', width:200, align: 'left',sortable:true }
            ]
        ],
        onLoadError: function (res) {
            AuthRoleRigthModel.ShowException(res);
        },
        onCheck: function (rowIndex, rowData) {
            var url = Onluy.basePath()+AuthRoleRigthModel.url+'/add';
            Onluy.ajax.getData(url,rowData,Onluy.secretkey, function(result){
                var success = result.success;
                //Onluy.easyui.ShowMsg(success ? "提示" : "错误",result.msg);
                if (success) {

                }
            },function(error){
                //AuthUserRigthModel.ShowException(error);
            } );
        },
        onUncheck: function (rowIndex, rowData) {
            var url = Onluy.basePath()+AuthRoleRigthModel.url+'/del';
            Onluy.ajax.getData(url,rowData,Onluy.secretkey, function(result){
                var success = result.success;
                //Onluy.easyui.ShowMsg(success ? "提示" : "错误",result.msg);
                if (success) {

                }
            },function(error){
                //AuthUserRigthModel.ShowException(error);
            } );
        },


        onBeforeLoad: function (param) {
            $('#AuthRoleRigth_Grid').datagrid('clearSelections');
            param['catchKey'] = Math.random();

            var datatype=$('#datatype_sel').combobox('getValue');
            param['datatype'] = datatype;

            var userrow=$('#AuthRole_Grid').datagrid('getSelected');
            if(userrow){
                param['roleid']=userrow['id'];
            }


            param['name'] = $('#AuthRoleRigth_ss').searchbox('getName');
            param['value'] = $('#AuthRoleRigth_ss').searchbox('getValue');
        }
    });
    //设置分页控件
    var p = $('#AuthRoleRigth_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



